package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class InfoBox  extends NokaTag{
	private static final long serialVersionUID = 7099686897489864061L;
	private String id = null;
	private String event=null;
	
	public int doStartTag()throws JspException{
		JspWriter jspOut = pageContext.getOut();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		String basePath = basepath(request);
		StringBuilder bodystr = new StringBuilder();
		bodystr.append(potjs(request));//js框架
		bodystr.append(nkBoxJsAndCss(request));
		bodystr.append(InfoBoxJS(request));
		bodystr.append("<script type=\"text/javascript\">");
		bodystr.append("Event.observe(document, 'dom:loaded', function() {");
		bodystr.append("var "+id+" = new ninfobox('"+basePath+"',["+(null==event?"":"'"+event.replace(",", "','")+"'")+"]);");
		bodystr.append(id+".show();");
		bodystr.append("});");
		bodystr.append("</script>");
		try {
			jspOut.write(bodystr.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getEvent() {
		return event;
	}

	public void setEvent(String event) {
		this.event = event;
	}
}
